package de.haw.adt.implementation;

import static de.haw.adt.implementation.Values.KILO;
import de.haw.adt.interfaces.IWork;

class Work extends AbstractPhysicalScalar implements IWork {

	private final double work;

	private Work(double work) {
		this.work = work;
	}
	
	@Override
	double getValue() {
		return work;
	}

	public int compareTo(IWork work) {
		return Double.compare(this.work, work.getJ());
	}

	@Override
	public boolean equals(Object o) {
		if (o == this)
			return true;
		if (!(o instanceof IWork))
			return false;
		return this.compareTo((IWork) o) == 0;
	}

	public double getJ() {
		return work;
	}

	public double getKJ() {
		return work / KILO;
	}

	public IWork add(IWork work) {
		return valueOf(this.work + work.getJ());
	}

	public IWork sub(IWork work) {
		return valueOf(this.work - work.getJ());
	}
	
	public static IWork valueOf(double work) {
		return new Work(work);
	}
}

